package com.qkjia.day03;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Test01_ThreadPool {
    public static void main(String[] args) {
        //1.创建固定数量线程的线程池 去银行柜台办理业务 适用于长期任务 性能更好
        //ExecutorService threadPool = Executors.newFixedThreadPool(3);
        //2.创建单个线程的线程池 任何时候都只有一个线程在执行 保证任务具有一定的顺序性
        //ExecutorService threadPool = Executors.newSingleThreadExecutor();
        //3.创建一个可扩展的线程池 适用于短时异步任务
        ExecutorService threadPool = Executors.newCachedThreadPool();
        for (int i = 0; i < 100; i++) {
            final int count = i;
            threadPool.execute(() -> {
                System.out.println(Thread.currentThread().getName() + "\t银行柜台为" + count + "位客户进行服务");
            });
        }
        threadPool.shutdown();
    }
}
